package com.xiao.mall.message.front;

import com.xiao.mall.message.service.UserNotificationService;
import com.xiao.mall.message.service.dto.front.NotificationFrontDto;
import com.xiao.mall.message.service.dto.front.UserNotificationFrontDto;
import com.xiao.mall.message.service.dto.front.UserNotificationTopicFrontDto;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.data.domain.Pageable;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/front/notification")
@Slf4j
@Deprecated
@Api(tags = "消息前台接口", value = "消息中心-消息对象")
public class NotificationFrontResource {

    private final UserNotificationService userNotificationService;
    public NotificationFrontResource(UserNotificationService userNotificationService) {
        this.userNotificationService = userNotificationService;
    }

    @ApiOperation("获取用户待阅读消息数量")
    @GetMapping("/count")
    public ResponseEntity<List<UserNotificationTopicFrontDto>> findNotificationTopicGroup(@RequestParam(name = "type") String type) {
        return ResponseEntity.ok(userNotificationService.findNotificationTopicGroupByUser(type));
    }

    @ApiOperation("查询用户相应主题分页消息")
    @GetMapping("")
    public ResponseEntity<List<UserNotificationFrontDto>> findNotificationPageByUser(@RequestParam(name = "type") String type,
                                                                                     @RequestParam(name = "topic") String topic,
                                                                                     Pageable pageable) {
        return ResponseEntity.ok().body(userNotificationService.findNotificationPageByUser(type, topic, pageable));
    }

    @ApiOperation("查询自己的消息")
    @PostMapping("/{messageId}/read")
    public ResponseEntity<NotificationFrontDto> readMessage(@PathVariable(name = "messageId") Long messageId) {
        return ResponseEntity.ok().body(userNotificationService.readMessage(messageId));
    }
}
